<template>
  <div class="trainerBox">
    <el-form
      @submit.native.prevent
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="门店名称" prop="schoolId">
        <el-select v-model="queryParams.schoolId" filterable clearable>
          <el-option label="全部" :value="undefined"></el-option>
          <el-option
            v-for="item in schools"
            :key="item.schoolId"
            :label="item.schoolName"
            :value="item.schoolId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="训练员" prop="teaUserId">
        <el-select v-model="queryParams.teaUserId" filterable clearable>
          <el-option label="全部" :value="undefined"></el-option>
          <el-option
            v-for="(item, index) in teachers"
            :key="index"
            :label="item.nickName"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          v-preventReClick
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          v-preventReClick
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
        <el-button
          v-preventReClick
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      height="320"
      border
      v-loading="loading"
      :data="postList"
      ref="tableRef"
    >
      <el-table-column
        show-overflow-tooltip
        label="门店名称"
        align="center"
        prop="schoolName"
      />
      <el-table-column
        show-overflow-tooltip
        label="训练员"
        align="center"
        prop="teaName"
      />
      <el-table-column
        show-overflow-tooltip
        label="学员数量"
        align="center"
        prop="stuNum"
      />
      <el-table-column
        show-overflow-tooltip
        label="未完成学员数量"
        align="center"
        prop="unFinishNum"
      />
      <el-table-column
        show-overflow-tooltip
        label="下发周期状态"
        align="center"
        prop="sendDurationStatus"
      >
        <template #header>
          下发周期状态<el-tooltip class="item" effect="dark" placement="bottom">
            <i
              class="el-icon-question shou"
              style="font-size: 16px; vertical-align: middle; margin-left: 5px"
            ></i>
            <div slot="content">（正常状态的数量/异常状态的数量）</div>
          </el-tooltip>
        </template></el-table-column
      >
      <el-table-column
        show-overflow-tooltip
        label="学习周期状态"
        align="center"
        prop="studyDurationStatus"
      >
        <template #header>
          学习周期状态<el-tooltip class="item" effect="dark" placement="bottom">
            <i
              class="el-icon-question shou"
              style="font-size: 16px; vertical-align: middle; margin-left: 5px"
            ></i>
            <div slot="content">（正常状态的数量/异常状态的数量）</div>
          </el-tooltip>
        </template></el-table-column
      >
      <el-table-column
        show-overflow-tooltip
        label="评价周期状态"
        align="center"
        prop="evaluateDurationStatus"
      >
        <template #header>
          评价周期状态<el-tooltip class="item" effect="dark" placement="bottom">
            <i
              class="el-icon-question shou"
              style="font-size: 16px; vertical-align: middle; margin-left: 5px"
            ></i>
            <div slot="content">（正常状态的数量/异常状态的数量）</div>
          </el-tooltip>
        </template></el-table-column
      >
      <el-table-column
        show-overflow-tooltip
        label="授权时间"
        align="center"
        prop="firstSetTime"
      >
        <template #header>
          授权时间<el-tooltip class="item" effect="dark" placement="bottom">
            <i
              class="el-icon-question shou"
              style="font-size: 16px; vertical-align: middle; margin-left: 5px"
            ></i>
            <div slot="content">2024/10/31后开始统计</div>
          </el-tooltip>
        </template></el-table-column
      ></el-table
    >
  </div>
</template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[10, 15, 20, 30, 40, 50]"
    />
  </div>
</template>

<script>
import { schoolList, teacherList } from "@/api/screen/courseLearningManagement";
import { studentNumList } from "@/api/screen/train";
export default {
  props: {
    active: [String, Number],
  },
  data() {
    return {
      loading: false,
      postList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teaUserId: undefined,
        schoolId: undefined,
      },
      total: 10,
      teachers: [],
      schools: [],
    };
  },
  mounted() {},
  watch: {
    active: {
      handler(newVal) {
        console.log("newVal", newVal);
        if (newVal == 0) {
          this.getList();
          this.getSchoolList();
          this.getTeacherList();
        }
      },
      immediate: true,
    },
  },
  methods: {
    async getSchoolList() {
      let res;
      try {
        res = await schoolList({
          pageNum: 1,
          pageSize: 9999,
        });
        if (res.code == 200) {
          this.schools = res.rows;
        }
      } finally {
      }
    },
    async getTeacherList() {
      let res;
      try {
        res = await teacherList({ pageNum: 1, pageSize: 9999 });
        if (res.code == 200) {
          this.teachers = res.rows;
        }
      } finally {
      }
    },
    async getList() {
      let res;
      try {
        this.loading = true;
        res = await studentNumList(this.queryParams);
        if (res.code == 200) {
          this.postList = res.rows;
          this.total = res.total;
          // 页面数据更新后，让表格滚动条回到顶部
          this.$nextTick(() => {
            if (this.$refs.tableRef) {
              this.$refs.tableRef.bodyWrapper.scrollTop = 0;
            }
          });
        }
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/screen/teacher/studentNumExport",
        {
          ...this.queryParams,
        },
        `studentNumExport_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.trainerBox {
  ::v-deep .el-table .el-table__header-wrapper tr th .cell {
    font-weight: 700 !important;
  }
}
</style>